﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace BonsaiScrum.Core.Query
{
    /// <summary>
    /// This class is used as a Data Transfer Object (DTO) to carry information from the
    /// persistance layer to the presentation layer.
    /// </summary>
    public class ProjectReport
    {
        public virtual int Id { get; private set; }
        public virtual string Name { get; private set; }
        public virtual string Description { get; private set; }

        public virtual ProjectStatus Status { get; private set; }

        public virtual ICollection<StoryReport> Stories { get; private set; }
        public virtual ICollection<SprintReport> Sprints { get; private set; }

        protected ProjectReport() { }

        [DisplayName("Percent Complete")]
        [UIHint("Percentage")]
        public virtual float PercentComplete
        {
            get { return Stories.Count == 0 ? 1 : Stories.Count(x => x.IsComplete()) / Stories.Count; }
        }

        public virtual ICollection<TaskReport> GetUnfinishedTasks()
        {
            var tasks = new List<TaskReport>();
            foreach (var story in Stories)
                tasks.AddRange(story.Tasks);

            return tasks;
        }
    }
}
